<?php
/**
 * Created by PhpStorm.
 * User: iraklis
 * Date: 12/8/13
 * Time: 6:43 PM
 */
session_start();
if (!isset($_SESSION["level"])) header("location:login.php");
include 'config.php';
include 'db_connection.php';

$userID = $_SESSION['u_id'];

$query = mysql_query("SELECT * FROM REMINDERS WHERE u_id = \"$userID\"");
if (!$query) {
    die('Invalid SELECT query: ' . mysql_error());
}
$count = mysql_num_rows($query);
$i = 1;
echo "[";
while ($rows = mysql_fetch_row($query)) {
    //printf("Title: %s, Start Date: %s,Start time: %d, Location: %s,Description: %s, Repeatition: %s, ",$rows[2], $rows[3],$rows[4], $rows[7],$rows[8], $rows[9],$rows[10]);
    //print_r($rows);
    //echo json_encode($rows);
    //$rows = mysql_fetch_row($query);
    //echo '{"id":'. $rows[1] .',"title":"'. "$rows[2]" . '", start":"' . "$rows[3]" . '","start_time":"' . "$rows[4]" . '","end":"'. "$rows[5]" .'","end_time":"' . "$rows[6]" . '","location":"' . "$rows[7]" . '","description":"' . "$rows[8]" . '","repeatition":"' . "$rows[9]" . '","remind_type":"' . "$rows[10]" . '"}';
    $repeatition = $rows[9];

    if ($repeatition == "daily") {
    }
    else if ($repeatition == "weekly") {
        echo '{"id":'. $rows[0] . ',"title":"' . $rows[2] . '", "start":"' . "$rows[3]" . '","start_time":"'. $rows[4] . '","end":"'. "$rows[5]" . '","end_time":"' . $rows[6] . '","allDay":false' . '},';
    }
    else if ($repeatition == "monthly") {}
    else if ($repeatition == "yearly") {}
    else if ($repeatition == "once") {}

    if ($i++ < $count) {
        echo '{"id":'. $rows[0] . ',"title":"' . $rows[2] . '", "start":"' . "$rows[3]" . '","start_time":"'. $rows[4] . '","end":"'. "$rows[5]" . '","end_time":"' . $rows[6] . '","allDay":false' . '},';
    } // end of if

    else {
        echo '{"id":'. $rows[0] . ',"title":"' . $rows[2] . '", "start":"' . "$rows[3]" . '","start_time":"'. $rows[4] . '","end":"'. "$rows[5]" . '","end_time":"' . $rows[6] . '","allDay":false' . '}';
    }// end of else

}
echo "]";
